Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: check all pending brackets have been closed when matching bracket #10712

Closed
wants to merge 1 commit into from

Conversation

Luv-Ray
Copy link
Contributor

@Luv-Ray Luv-Ray commented May 7, 2024

When asking matching bracket, we check all pending brackets have been closed in plain text:

let mut open_cnt = 1;
for (i, candidate) in chars_iter.take(MAX_PLAINTEXT_SCAN).enumerate() {
    if candidate == bracket {
        open_cnt += 1;
    } else if candidate == matching_bracket {
        if open_cnt == 1 {
            return Some(if is_fwd {
                cursor_pos + i + 1
            } else {
                cursor_pos - i - 1
            });
        }
        open_cnt -= 1;
    }
}

And we didn't check it if there an tree-sitter for this language.
However, some language's indents.scm may be rudimentary. If there is multiple matching brackets within the same node, the indents will become incorrect. This PR add this check so that the indents are at least as good as when there is no language support available.

An example in protobuf, write following intest.proto:
before
And after the fix:
after

@pascalkuthe
Copy link
Member

The same thing (plus more improvements) are already implemented in #10613

@pascalkuthe
Copy link
Member

I don't think this relates to indent tough that does not use match_bracket at all

@Luv-Ray Luv-Ray closed this May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants